package servlet;
import dao.MetaverseProductMapper;
import org.apache.ibatis.session.SqlSession;
import utils.MyBatisUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/metaverseProductDelServlet")
public class metaverseProductDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        SqlSession sqlSession=null;
        PrintWriter out = response.getWriter();
        try {
            sqlSession= MyBatisUtil.createSqlSession();
            int id= Integer.parseInt(request.getParameter("id"));
            int count=sqlSession.getMapper(MetaverseProductMapper.class).delete(id);
            sqlSession.commit();
            if(count>0){
                out.print("true");
            }else{
                out.print("false");
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
